<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>微信回调页面</title>
  <script src="./js/plugins/axios.js"></script>
  <script src="./js/plugins/vue.js"></script>
  <script src="./common/common.js"></script>
</head>
<body>
<div id="app">
</div>
</body>
<script type="text/javascript">
  new Vue({
    el:"#app",
    methods:{

    },
    mounted(){
      // http://bugtracker.itsource.cn/callback.html?code=061IduGa1839qC02jlIa1NmHxX1IduGX&state=1
      //从地址栏解析code出来
      let parse = parseUrlParams2Obj(location.href)
      let params = {
        "code" : parse.code
      }
      this.$http.post("/login/wechat",params).then(res=>{
        console.log(res)
        if(res.data.msg == 'NoBind'){
          //跳转绑定页面
          location.href = "/bind.html?unionid="+res.data.data
        }else {
          if(parse.state == "yyds"){
            location.href = "/index.html"
          }else {
            location.href = "/"+parse.state+".html"
          }

          localStorage.setItem("token",res.data.data.token);
          //把对象转换为json字符串存放
          localStorage.setItem("loginInfo",JSON.stringify(res.data.data.logininfo));
        }
        //有3种情况
        //1.已经注册过  也绑定了  直接登录  保存token 和 用户信息  跳转页面
        //2.注册过   没有绑定手机号   跳转到手机绑定页面
        //3.存的第一次  直接跳转注册页面
      })
    },
  })

</script>
</html>
